@import '../core/style/variables';
@import '../core/style/elevation';
@import '../core/style/layout-common';
@import '../core/a11y/a11y';


// Mixin to help with defining LTR/RTL 'transform: translate3d()' values.
// @param $open The translation value when the sidenav is opened.
// @param $close The translation value when the sidenav is closed.
@mixin mat-sidenav-transition($open, $close) {
  transform: translate3d($close, 0, 0);

  &.mat-sidenav-closed {
    // We use 'visibility: hidden | visible' because 'display: none' will not animate any
    // transitions, while visibility will interpolate transitions properly.
    // see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility, the Interpolation
    // section.
    visibility: hidden;
  }

  &.mat-sidenav-opening, &.mat-sidenav-opened {
    transform: translate3d($open, 0, 0);
  }
}

// Mixin that creates a new stacking context.
// see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
@mixin mat-sidenav-stacking-context() {
  position: relative;

  // Use a transform to create a new stacking context.
  transform: translate3d(0, 0, 0);
}

.mat-sidenav-container {
  // We need a stacking context here so that the backdrop and drawers are clipped to the
  // MdSidenavContainer. This creates a new z-index stack so we use low numbered z-indices.
  // We create another stacking context in the '.mat-sidenav-content' and in each sidenav so that
  // the application content does not get messed up with our own CSS.
  @include mat-sidenav-stacking-context();

  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;

  // Need this to take up space in the layout.
  display: block;

  // Hide the sidenavs when they're closed.
  overflow: hidden;

  // TODO(hansl): Update this with a more robust solution.
  &[fullscreen] {
    @include mat-fill();

    &.mat-sidenav-opened {
      overflow: hidden;
    }
  }
}

.mat-sidenav-backdrop {
  @include mat-fill();

  display: block;

  // Because of the new stacking context, the z-index stack is new and we can use our own
  // numbers.
  z-index: 2;

  // We use 'visibility: hidden | visible' because 'display: none' will not animate any
  // transitions, while visibility will interpolate transitions properly.
  // see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility, the Interpolation
  // section.
  visibility: hidden;

  &.mat-sidenav-shown {
    visibility: visible;
  }

  @include cdk-high-contrast {
    opacity: 0.5;
  }
}

.mat-sidenav-content {
  @include mat-sidenav-stacking-context();

  display: block;
  height: 100%;
  overflow: auto;
}

.mat-sidenav {
  @include mat-sidenav-stacking-context();

  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  min-width: 5vw;
  outline: 0;
  box-sizing: border-box;
  height: 100%;
  overflow-y: auto; // TODO(kara): revisit scrolling behavior for sidenavs

  @include mat-sidenav-transition(0, -100%);

  &.mat-sidenav-side {
    z-index: 1;
  }

  &.mat-sidenav-end {
    right: 0;

    @include mat-sidenav-transition(0, 100%);
  }

  [dir='rtl'] & {
    @include mat-sidenav-transition(0, 100%);

    &.mat-sidenav-end {
      left: 0;
      right: auto;

      @include mat-sidenav-transition(0, -100%);
    }
  }

  &.mat-sidenav-opening, &.mat-sidenav-opened {
    &:not(.mat-sidenav-side) {
      // The elevation of z-16 is noted in the design specifications.
      // See https://material.io/guidelines/patterns/navigation-drawer.html#
      @include mat-elevation(16);
    }
  }
}
